<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/7/14
 * Time: 0:09
 */

include("../utils/MysqlUtils.php");
include("../utils/ProjectConstant.php");

//管理User表的相应操作
class UserDao{
    var $mysqlUtils;

    function __construct(){
        $this->mysqlUtils = new MysqlUtils();
    }

    function login($request_param){
        $param_arr=(Array)json_decode($request_param);

        $username=$param_arr[0]->username;
        $pwd=$param_arr[0]->pwd;

        $sql = "select 1 as rlt from user where username = '".$username."' and pwd ='".$pwd."';";

        $result=mysql_query($sql);

        $backResult = "";

        while ($row=mysql_fetch_assoc($result))//与$row=mysql_fetch_assoc($result)等价
        {
            if($row["rlt"]==1){
                $backResult = ProjectConstant::$RETURN_SUCCESS;
            }else{
                $backResult = ProjectConstant::$RETURN_FAIL;
            }
        }

        mysql_free_result($result);
        return $backResult;
    }

    //注册，保存信息
    function register($request_param, $RETURN_SUCCESS){
        $param_arr=(Array)json_decode($request_param);

        $sql = "insert into user(user_id,uname,pwd,umail,phone_num,image_local_path,image_path)"
                ."values (null,'$param_arr[0]->uname','$param_arr[0]->pwd',"
                ."'$param_arr[0]->umail','$param_arr[0]->phone_num','"
                ."$param_arr[0]->image_local_path','$param_arr[0]->image_path')";


        if(mysql_query($sql)){
            return ProjectConstant::$RETURN_SUCCESS;
        }else{
            return ProjectConstant::$RETURN_FAIL;
        }
    }

    //修改信息
    function updateUser($request_param){

    }

    function deconnection(){
        mysql_close($this->connect);
    }

}




?>